package ShenBlueCenter.Inc;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import ShenBlueDao.LoginDao;
import ShenBlueInc.Center.Login_Center;

/**
 * Servlet implementation class LoginUser
 */
@WebServlet("/LoginUser")
public class LoginUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginUser() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest res, HttpServletResponse rep) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String name=res.getParameter("name");
		String Pwd=res.getParameter("password");
		rep.setContentType("application/json");
		rep.setCharacterEncoding("utf8");
		Login_Center loginc=new Login_Center();
		if(loginc.SelectLogin(name, Pwd)) {
			rep.getWriter().append("{\"error\":\"您的用户名或者密码错误\"}");
			return;
		}
		System.out.println(name+" "+Pwd);
		LoginDao LoginDao=loginc.SelectLoginMsg(name, Pwd);
		
		HttpSession session=res.getSession();
		session.setAttribute("User_id", LoginDao.getId());
		session.setAttribute("User_telephone", LoginDao.getTelephone());
		session.setAttribute("User_name", LoginDao.getName());
		session.setAttribute("User_Password", LoginDao.getPassword());
		session.setAttribute("User_email", LoginDao.getEmail());
		session.setAttribute("User_fullname", LoginDao.getFullname());
		rep.getWriter().append("{\"msg\":\"登录成功\"}");
		return;
	}

}
